home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
libimp
/
impRowMath.c.z
/
impRowMath.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
14KB
|
582 lines
/**************************************************************************
*
* Copyright (c) 1993 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: impRowMath.c
*
* Description: Perform mathmatical operations on image rows.
*
**************************************************************************/
#ident "$Revision: 1.2 $"
#include <stdio.h>
#include <bstring.h>
#include <assert.h>
#include "impI.h"
/**************************************************************************
*
* Function: impZeroRow
*
* Description: Initializes a row of pixels to 0.
*
* Parameters:
* dptr (I) - row to zero
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impZeroRow(short *dptr, int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
bzero(dptr, n * sizeof(short));
}
/**************************************************************************
*
* Function: impInitRow
*
* Description: Initializes a row of pixels to the specified value.
*
* Parameters:
* dptr (I) - row to initialize
* val (I) - value to initialize row
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impInitRow(register short *dptr, register int val, register int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
if (val == 0)
impZeroRow(dptr, n);
else {
while (n >= 8) {
dptr[0] = (short)val;
dptr[1] = (short)val;
dptr[2] = (short)val;
dptr[3] = (short)val;
dptr[4] = (short)val;
dptr[5] = (short)val;
dptr[6] = (short)val;
dptr[7] = (short)val;
dptr += 8;
n -= 8;
}
while (n--)
*dptr++ = (short)val;
}
}
/**************************************************************************
*
* Function: impCopyRow
*
* Description: Copies a row of pixels from source to desitination.
* Source and destination can be the same.
*
* destination = source
*
* Parameters:
* dptr (O) - destination row
* sptr (I) - source row
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impCopyRow(short *dptr, short *sptr, int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
assert(sptr != NULL);
/*
* If dptr == sptr we can optimize the processing
*/
if (sptr == dptr)
return;
bcopy(sptr, dptr, n * sizeof(short));
}
/**************************************************************************
*
* Function: impSAddRow
*
* Description: Performs scalar addition on the specified source row. The
* scalar value is added to the source row and the result is
* placed in the destination row. The source and destination rows
* can be the same.
*
* destination = source + value
*
* Parameters:
* dptr (O) - destination row
* sptr (I) - source row
* val (I) - value to add to the source row
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impSAddRow(register short *dptr, register short *sptr,
register int val, register int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
assert(sptr != NULL);
/*
* If dptr == sptr we can optimize the processing
*/
if (sptr == dptr) {
while (n >= 8) {
dptr[0] += val;
dptr[1] += val;
dptr[2] += val;
dptr[3] += val;
dptr[4] += val;
dptr[5] += val;
dptr[6] += val;
dptr[7] += val;
dptr += 8;
n -= 8;
}
while (n--) {
*dptr = (*dptr) + val;
dptr++;
}
} else {
while (n >= 8) {
dptr[0] = sptr[0] + val;
dptr[1] = sptr[1] + val;
dptr[2] = sptr[2] + val;
dptr[3] = sptr[3] + val;
dptr[4] = sptr[4] + val;
dptr[5] = sptr[5] + val;
dptr[6] = sptr[6] + val;
dptr[7] = sptr[7] + val;
dptr += 8;
sptr += 8;
n -= 8;
}
while (n--)
*dptr++ = (*sptr++) + val;
}
}
/**************************************************************************
*
* Function: impVAddRow
*
* Description: Performs vector addition of the specified source rows
* placing the result in the destination row.
*
* destination = source1 + source2
*
* Parameters:
* dptr (O) - destination row
* sptr1 (I) - source row 1
* sptr2 (I) - source row 2
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impVAddRow(register short *dptr, register short *sptr1,
register short *sptr2, register int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
assert(sptr1 != NULL);
assert(sptr2 != NULL);
while (n >= 8) {
dptr[0] = sptr1[0] + sptr2[0];
dptr[1] = sptr1[1] + sptr2[1];
dptr[2] = sptr1[2] + sptr2[2];
dptr[3] = sptr1[3] + sptr2[3];
dptr[4] = sptr1[4] + sptr2[4];
dptr[5] = sptr1[5] + sptr2[5];
dptr[6] = sptr1[6] + sptr2[6];
dptr[7] = sptr1[7] + sptr2[7];
dptr += 8;
sptr1 += 8;
sptr2 += 8;
n -= 8;
}
while (n--) {
*dptr = (*sptr1) + (*sptr2);
sptr1++;
sptr2++;
dptr++;
}
}
/**************************************************************************
*
* Function: impSSubRow
*
* Description: Performs scalar subtraction on the specified source row. The
* scalar value is subtracted from the source row and the result is
* placed in the destination row. The source and destination rows
* can be the same.
*
* destination = source - value
*
* Parameters:
* dptr (O) - destination row
* sptr (I) - source row
* val (I) - value to subtracted from the source row
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impSSubRow(register short *dptr, register short *sptr,
register int val, register int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
assert(sptr != NULL);
/*
* If dptr == sptr we can optimize the processing
*/
if (sptr == dptr) {
while (n >= 8) {
dptr[0] -= val;
dptr[1] -= val;
dptr[2] -= val;
dptr[3] -= val;
dptr[4] -= val;
dptr[5] -= val;
dptr[6] -= val;
dptr[7] -= val;
dptr += 8;
n -= 8;
}
while (n--) {
*dptr = (*dptr) - val;
dptr++;
}
} else {
while (n >= 8) {
dptr[0] = sptr[0] - val;
dptr[1] = sptr[1] - val;
dptr[2] = sptr[2] - val;
dptr[3] = sptr[3] - val;
dptr[4] = sptr[4] - val;
dptr[5] = sptr[5] - val;
dptr[6] = sptr[6] - val;
dptr[7] = sptr[7] - val;
dptr += 8;
sptr += 8;
n -= 8;
}
while (n--)
*dptr++ = (*sptr++) - val;
}
}
/**************************************************************************
*
* Function: impVSubRow
*
* Description: Performs vector subtraction of the specified source rows
* placing the result in the destination row.
*
* destination = source1 - source2
*
* Parameters:
* dptr (O) - destination row
* sptr1 (I) - source row 1
* sptr2 (I) - source row 2
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impVSubRow(register short *dptr, register short *sptr1,
register short *sptr2, register int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
assert(sptr1 != NULL);
assert(sptr2 != NULL);
while (n >= 8) {
dptr[0] = sptr1[0] - sptr2[0];
dptr[1] = sptr1[1] - sptr2[1];
dptr[2] = sptr1[2] - sptr2[2];
dptr[3] = sptr1[3] - sptr2[3];
dptr[4] = sptr1[4] - sptr2[4];
dptr[5] = sptr1[5] - sptr2[5];
dptr[6] = sptr1[6] - sptr2[6];
dptr[7] = sptr1[7] - sptr2[7];
dptr += 8;
sptr1 += 8;
sptr2 += 8;
n -= 8;
}
while (n--) {
*dptr = (*sptr1) - (*sptr2);
sptr1++;
sptr2++;
dptr++;
}
}
/**************************************************************************
*
* Function: impSMulRow
*
* Description: Performs scalar multiplication on the specified source row.
* The source row is multiplied by the specified constant and the
* result is placed in the destination row. The source and destination
* rows can be the same.
*
* destination = source * value
*
* Parameters:
* dptr (O) - destination row
* sptr (I) - source row
* val (I) - value to multiply the source row
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impSMulRow(register short *dptr, register short *sptr,
register int val, register int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
assert(sptr != NULL);
/*
* If dptr == sptr we can optimize the processing
*/
if (sptr == dptr) {
while (n >= 8) {
dptr[0] *= val;
dptr[1] *= val;
dptr[2] *= val;
dptr[3] *= val;
dptr[4] *= val;
dptr[5] *= val;
dptr[6] *= val;
dptr[7] *= val;
dptr += 8;
n -= 8;
}
while (n--) {
*dptr = (*dptr) * val;
dptr++;
}
} else {
while (n >= 8) {
dptr[0] = sptr[0] * val;
dptr[1] = sptr[1] * val;
dptr[2] = sptr[2] * val;
dptr[3] = sptr[3] * val;
dptr[4] = sptr[4] * val;
dptr[5] = sptr[5] * val;
dptr[6] = sptr[6] * val;
dptr[7] = sptr[7] * val;
dptr += 8;
sptr += 8;
n -= 8;
}
while (n--)
*dptr++ = (*sptr++) * val;
}
}
/**************************************************************************
*
* Function: impSDivRow
*
* Description: Performs scalar division on the specified source row. The
* source row is divided by the specified constant and the result is
* placed in the destination row. The source and destination rows
* can be the same.
*
* destination = source / value
*
* Parameters:
* dptr (O) - destination row
* sptr (I) - source row
* val (I) - value to divide into the source row
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
void impSDivRow(register short *dptr, register short *sptr,
register int val, register int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
assert(sptr != NULL);
assert(val != 0);
/*
* If dptr == sptr we can optimize the processing
*/
if (sptr == dptr) {
while (n >= 8) {
dptr[0] /= val;
dptr[1] /= val;
dptr[2] /= val;
dptr[3] /= val;
dptr[4] /= val;
dptr[5] /= val;
dptr[6] /= val;
dptr[7] /= val;
dptr += 8;
n -= 8;
}
while (n--) {
*dptr = (*dptr) / val;
dptr++;
}
} else {
while (n >= 8) {
dptr[0] = sptr[0] / val;
dptr[1] = sptr[1] / val;
dptr[2] = sptr[2] / val;
dptr[3] = sptr[3] / val;
dptr[4] = sptr[4] / val;
dptr[5] = sptr[5] / val;
dptr[6] = sptr[6] / val;
dptr[7] = sptr[7] / val;
dptr += 8;
sptr += 8;
n -= 8;
}
while (n--)
*dptr++ = (*sptr++) / val;
}
}
/**************************************************************************
*
* Function: impClampRow
*
* Description: Clamps the value of the source row between the specified
* lo and hi values inclusive. The result is placed in the destination
* row. The source and destination rows can be the same.
*
* Parameters:
* dptr (O) - destination row
* sptr (I) - source row
* lov (I) - lo clamp value
* hiv (I) - high clamp value
* n (I) - number of pixels in row
*
* Return: none
*
**************************************************************************/
/* Clamping macro */
#define CLAMP_VAL(v,lov,hiv) (((v) < (lov)) ? (lov): \
(((v) > (hiv)) ? (hiv): (v)))
void impClampRow(register short *dptr, register short *sptr,
register int lov, register int hiv, register int n)
{
/*
* Sanity check the inputs
*/
assert(dptr != NULL);
assert(sptr != NULL);
while (n >= 8) {
dptr[0] = (short)CLAMP_VAL(sptr[0], lov, hiv);
dptr[1] = (short)CLAMP_VAL(sptr[1], lov, hiv);
dptr[2] = (short)CLAMP_VAL(sptr[2], lov, hiv);
dptr[3] = (short)CLAMP_VAL(sptr[3], lov, hiv);
dptr[4] = (short)CLAMP_VAL(sptr[4], lov, hiv);
dptr[5] = (short)CLAMP_VAL(sptr[5], lov, hiv);
dptr[6] = (short)CLAMP_VAL(sptr[6], lov, hiv);
dptr[7] = (short)CLAMP_VAL(sptr[7], lov, hiv);
dptr += 8;
sptr += 8;
n -= 8;
}
while (n--) {
*dptr++ = (short)CLAMP_VAL(*sptr, lov, hiv);
sptr++;
}
}